<?php

namespace App\Controller\Call;

use App\Controller\BaseController;
use App\Request\Call\AnswerAliveRequest;
use App\Request\Call\LaunchAliveRequest;
use App\Services\Call\AliveService;
use Hyperf\Context\Context;
use Hyperf\Di\Annotation\Inject;

class AliveController extends BaseController
{
    #[Inject]
    public AliveService $aliveService;


    /**
     * Note - 接听方每6秒请求一次的接口（在answer成功之后立刻发起）
     * DateTime 2024/8/21 17:43
     * User Admin
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function answerAlive(AnswerAliveRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);
        $userInfo = Context::get('user');
        $result = $this->aliveService->answerAlive($userInfo, $params);
        return $this->return($result);
    }


    /**
     * Note - 发起方每6秒请求一次的接口（收到第一帧流就请求）
     * DateTime 2024/8/21 18:13
     * User Admin
     * @param LaunchAliveRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function launchAlive(LaunchAliveRequest $request)
    {
        $params = $this->request->post();
        $request->execute($params);
        $userInfo = Context::get('user');
        $result = $this->aliveService->launchAlive($userInfo, $params);
        return $this->return($result);
    }

}